package com.web;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/book/logout")
public class LogoutServlet extends HttpServlet {
    /**
     * 注销的方法
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("开始注销");
        // 创建 session 对象
        HttpSession session = req.getSession();
        // 将整个 session 对象都销毁掉
        session.invalidate();
        // 转发到主页面
        req.getRequestDispatcher("/book/list").forward(req, resp);
        // 重定向到主页面
        // resp.sendRedirect("/book/list");
    }
}
